<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />
    <ex_super_table_page v-bind="option" ref="SuperTablePage" :autoPage="false" @selection-change="e => selection = e">
      <template v-slot:fileName="{ row }">
        <a v-if="row.filePath" class="a_file_link" target="_blank" :href="$ex_default_download_url + row.filePath"
          :download="row.fileName"><i class="el-icon-download el-icon--left" />{{ row.fileName }}</a>
      </template>
    </ex_super_table_page>
    <ex_super_dialog_form ref="formDialog"  v-bind="dialog" @afterSubmitSuccess="submitAfter">
    </ex_super_dialog_form>

  </div>
</template>
<script>
import superTablePageFunction from '@/mixin/super-table-page-function';

import page_table_model_manage from '@/mixin/page_table_model_manage';
import emitOnFunction from '@/mixin/emit-on-function';
let emitKey = 'fileTemplate>manage'
export default {
  title: 'label_file_template_manage',
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage, ],
  components: {},
  data() {
    return {
      selection: [],
      option: {
        search: {
          model: [
            { label: "label_system", key: "service", type: 'select', enum: 'BaseSystemEnum' },
            { label: "label_module", key: "module", type: 'select', enum: 'BaseOmsModuleEnum' },

          ],
        },
        action: [
          {
            label: { _key: 'label_new_any',i18n: true, type: 'label_file_template' }, attrs: { icon: "el-icon-plus" }, click: () => {
              this['$refs']['formDialog'].showNew({
                title:this.$tt({ _key: 'label_new_any',i18n: true, type: 'label_file_template' }),
              })
            }
          },
        ],

        table: {
          url: "/oms-api/base/OmsBaseTemplateRpc/selectAll.json",
          model: this.init_table_model(),
        },
      },

      dialog: {
        customClass: 'dialog_auto',
        submitUrl: '/oms-api/base/OmsBaseTemplateRpc/save.json',
        submitDataHandle: (data) => {
          return _.pickBy(data, (v, k) => k != 'file')
        },
        form: {
          itemClass: "form_item_default", inputClass: "form_input_default",
          default: { service: 'OMS' },


          model: [
            { header: "label_base_info", },

            {
              key: 'service', label: 'label_system', type: 'select', enum: 'BaseSystemEnum',
              disabled: true,
            },
            { key: 'module', label: 'label_module', type: 'select', enum: 'BaseOmsModuleEnum' },
            {
              key: 'file', label: 'label_file_template', type: 'ex-upload-file', attrs: {
                limit: 1,
              },
              keyExtra: { _emitKey: 'input', '[0].filePath': 'filePath', '[0].fileName': 'fileName', '[0].fileExt': 'fileType' }
            },

          ],
          rules: {
            'service': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
            'module': [{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'change' }],
            'file': [{ required: true, type: 'array', message: this.$tt('tip_can_no_empty'), trigger: 'change' }],

          },
        }
      },
    };
  },
  methods: {
    option_table_model() {
      return [
        {
          key: 'service', label: 'label_system', 'width': 120, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$enumShow(v, "BaseSystemEnum")
        },
        {
          key: 'module', label: 'label_module', 'width': 120, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$enumShow(v, "BaseOmsModuleEnum")
        },


        {
          key: 'fileName', label: 'label_file_name', 'min-width': 120, 'show-overflow-tooltip': true,
          render: (h, { row }) => {
            if (!row.filePath) return
            return (<a class="a_file_link" target="_blank" href={this.$ex_default_download_url + row.filePath}
              download={row.fileName}><i class="el-icon-download el-icon--left" />{row.fileName}</a>)
          }

        },
        { key: 'fileType', label: 'label_file_type', 'width': 120, 'show-overflow-tooltip': true, },
        { key: 'filePath', label: 'label_file_path', 'width': 120, 'show-overflow-tooltip': true, },
        {
          type: 'operate', width: 210, operate: [
            {
              label: 'label_delete', 
              auth:'oms_file_template_delete',
              type: "confirm-button", url: '/oms-api/base/OmsBaseTemplateRpc/remove.json', message: 'label_fms_bank_card_confirm_delete',
              buttonClass: "button_text_danger", confirmButtonType: 'danger',
              params: (row) => { return { "id": row["id"] } }, done: ['reload', 'tip']
            },

          ]
        },
      ]
    },
    print(rows) {
      this.$refs.common_print_dialog.show(rows)
    },
    submitAfter() {
      this.reload()
      this.$refreshStoreCommonDataGroup('/oms-api/base/OmsBaseTemplateRpc/selectAll.json')
    },

  }
};

</script>
<style></style>
